package agents.interaction;

import game.constants.ReferenceAgent;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.HumanInteraction;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionEquipe;
import constants.Constants;
import extra.ObjectId;

public class InteractionEquipeObject extends HumanInteraction {
	
	ObjectId objectIdToEquipe;

	@Override
	public void initializeParametersList() {
		objectIdToEquipe = new ObjectId();
		addParameter(objectIdToEquipe);
		
	}

	@Override
	public void initializeActionList() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initializeSpecialFeatures() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initializeName() {
		name="Equipe Object";
		
	}

	@Override
	public void initializeId() {
		this.id=ReferenceAgent.AGENT_HUMAN_INTERACTION_EQUIPE_OBJECT;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {
		WorldObject objectToEquipe = universe.getObject(objectIdToEquipe.getObjectId());
		if(objectToEquipe==null){
			isActive=false;
			return;
		}
		//i search if the object already has a similar object equiped
		for(WorldObject obj : object.getListObjects()){
			SpetialFeature equipe = obj.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_OBJECT_EQUIPED);
			if(equipe==null){
				continue;
			}
			if(equipe.getValue()==Constants.FALSE){
				continue;
			}
			if(obj.getType()==objectToEquipe.getType()){
				//desequipo el objeto o trato de generar la accion sobre el
				isActive=false;
				return;
			}
		}
		ActionEquipe actionEquipe = new ActionEquipe();
		actionEquipe.setSource(object);
		actionEquipe.setTarget(objectToEquipe);
		universe.setAction(actionEquipe);
		isActive=false;
		
		
	}

	
	
}
